class Solution {
public:
    vector<int> findBall(vector<vector<int>>& grid)
    {
        int m = grid.size(), n = grid[0].size();
        vector<int> ans;
        bool flag = false;
        for (int i = 0; i < n; i++)
        {
            int col = i;
            for (int j = 0; j < m; j++)
            {
                int dir = grid[j][col];
                col += grid[j][col];
                if (col < 0 || col == n || grid[j][col] != dir)
                {
                    col = -1;
                    break;
                }
            }
            ans.push_back(col);
        }
        return ans;
    }
};